<template>
  <v-app id="inspire">
    <v-content>
      <v-container>
        <h1 style="text-align: center">Discussion</h1>

          <v-simple-table>
            <template v-slot:default>
              <thead>
              <tr>
                <th scope="col" class="text-left">Discussion Title</th>
                <th scope="col" class="text-left">Meeting</th>
                <th scope="col" class="text-left">Type</th>
              </tr>
              </thead>
              <tbody>
              <tr v-for="(item,index) in discussions" :key="index"
                  @click="enterDiscussion(item)"
              >
                <td >{{ item.title }}</td>
                <td>{{ item.meetingFullName }}</td>
                <td v-if="item.type === 1">第一次讨论</td>
                <td v-else>第二次讨论</td>
              </tr>
              </tbody>
            </template>
          </v-simple-table>
        <side-bar></side-bar>
      </v-container>
    </v-content>
  </v-app>
</template>

<script>
  import SideBar from './Components/SideBar'
  import store from '../store'
  export default {
    name: 'discussion',
    components: {
      SideBar
    },
    data () {
      const generateMyDiscussions = _ => {
        const discussions = []
        this.$axios.post('/myDiscussions', store.state.userName)
          .then(resp => {
            console.log(resp)
            if (resp != null) {
              var response = resp.data
              response.forEach((discussion, index) => {
                discussions.push({
                  title: discussion.title,
                  meetingFullName: discussion.meetingFullName,
                  type: discussion.type,
                  status: discussion.status
                })
              })
              return discussions
            } else return null
          })
          .catch(error => {
            console.log(error)
          })
        return discussions
      }
      return {
        discussions: generateMyDiscussions()
      }
    },
    methods: {
      enterDiscussion(item){
        this.$router.push({
          path: '/adiscussion/' + item. meetingFullName,
          query: {
            title: item.title,
            type: item.type
            // topics: item.topics
          }
        })
      }
    }
  }
</script>
